package org.linlinjava.litemall.wx.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.linlinjava.litemall.core.config.DynamicTimeZoneConfiguration;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallShop;
import org.linlinjava.litemall.db.dto.AdminShopSpecialDateDTO;
import org.linlinjava.litemall.db.service.LitemallShopService;
import org.linlinjava.litemall.db.util.CompletionDateUtils;
import org.linlinjava.litemall.wx.annotation.LogAnno;
import org.linlinjava.litemall.wx.service.WxShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;

/**
 * 车间控制器
 *
 * @author yliyun
 * @description：门店
 * @date 2022/09/14
 */
@Api(tags = "门店API")
@RestController
@RequestMapping("/wx/shop")
@Validated
public class ShopController {
    /**
     * litemall店服务
     */
    @Autowired
    private LitemallShopService litemallShopService;
    /**
     * 店服务
     */
    @Autowired
    private WxShopService shopService;

    /**
     * 所有
     *
     * @param longitude 经度
     * @param latitude  纬度
     * @param type      类型（1：自取；2：配送）
     * @return {@link Object}
     */
    @ApiOperation("APP门店列表")
    @GetMapping("all")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "page"),
            @ApiImplicitParam(name = "limit",value = "limit")
    })
    @LogAnno
    public Object all(BigDecimal longitude, BigDecimal latitude, Integer type
                    ,@RequestParam(value = "page",defaultValue = "1") Integer page
                    ,@RequestParam(value = "limit",defaultValue = "900")  Integer limit){
        return shopService.all(longitude, latitude, type,page,limit);
    }


    /**
     * 细节
     *
     * @param id id
     * @return {@link Object}
     */
    @GetMapping("detail")
    @LogAnno
    public Object detail(@NotNull Integer id){
        return ResponseUtil.ok(litemallShopService.findById(id));
    }

    /**
     * 地区时区门店判断
     * 判断当前时间是否与给定店铺的时间相同。
     * @param shopId 门店id
     * @return {@link Object}
     */
    @ApiOperation("APP地区时区门店判断")
    @GetMapping("regionTimeShop")
    @LogAnno
    public Object regionTimeShop(Integer shopId){
        return shopService.regionTimeShop(shopId);
    }

}
